//
//  ImageListViewController.swift
//  test-ios
//
//  Created by wyz5204 on 2023/2/11.
//

import UIKit

class ImageListViewController: UIViewController , UITableViewDelegate , UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ImageCell", for: indexPath) as! ImageViewCell
        cell.bind(self.data[indexPath.row])
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print(self.data[indexPath.row])
        let a = storyboard?.instantiateViewController(withIdentifier: "ImageDetail") as? ImageDetailController ?? nil
        guard a != nil else{
            return
        }
        
        a?.imgName = self.data[indexPath.row]
        
        navigationController?.pushViewController(a!, animated: true)
//        present(a!, animated:true)
        
    }
    
    var data : [String] = []
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
            
        for index in 0...26 {
            data.append("lif\(index)")
        }
        print(data)
        let imageListView: UITableView = UITableView()
        imageListView.dataSource = self
        imageListView.delegate = self
        imageListView.register(ImageViewCell.self, forCellReuseIdentifier: "ImageCell")
        imageListView.addTo(self.view) { view in
            view.snp.makeConstraints { make in
                make.left.equalTo(self.view.snp.left)
                make.right.equalTo(self.view.snp.right)
                make.top.equalTo(self.view.snp.top)
                make.bottom.equalTo(self.view.snp.bottom)
            }
        }
    }
    
    
    
}
